package raf.presentation;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import raf.neural.NeuralNetwork;

public class MainWindow extends JFrame implements ActionListener {

	public MainWindow() {
		initGui();
	}
	
	private void initGui() {
		getContentPane().add(getConfigurationField());
		getContentPane().add(getLabel());
		getContentPane().add(getOKButton());
		getContentPane().add(getStatusLabel());
		getContentPane().add(getInputs());
		setBounds(100, 100, 200, 600);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(null);
		setVisible(true);
	}
	
	private JTextField configurationField;
	private JLabel label;
	private JButton okButton;
	private JLabel statusLabel;
	private JTextArea inputs;
	
	private JTextArea getInputs() {
		if(inputs==null) {
			inputs = new JTextArea();
			inputs.setBounds(10, 110, 180, 200);
			inputs.setAutoscrolls(true);
			inputs.setWrapStyleWord(true);
		}
		return inputs;
	}
	
	private JLabel getStatusLabel() {
		if(statusLabel==null) {
			statusLabel=new JLabel("nothing");
			statusLabel.setBounds(10, 550, 180, 20);
		}
		return statusLabel;
	}
	
	private JTextField getConfigurationField() {
		if(configurationField==null) {
			configurationField = new JTextField();
			configurationField.setBounds(10,50,180,20);
			configurationField.setToolTipText("input[-layer]*");
		}
		return configurationField;
	}
	
	private JLabel getLabel() {
		if(label==null) {
			label = new JLabel("Network configuration", SwingConstants.CENTER);
			label.setBounds(10, 20, 180, 20);
		}
		return label;
	}
	
	private JButton getOKButton() {
		if(okButton==null) {
			okButton=new JButton("OK");
			okButton.setBounds(30, 80, 140, 20);
			okButton.addActionListener(this);
		}
		return okButton;
	}
	
	private NeuralNetwork network;
	
	public static void main(String[] args) {
		new MainWindow();
	}

	public void actionPerformed(ActionEvent e) {
		network = new NeuralNetwork(configurationField.getText());
		network.initialize();
		okButton.setEnabled(false);
		statusLabel.setText("inited");
		System.out.println(network);
	}
}
